package cn.kxx.service.impl;

import cn.kxx.mapper.RoleMapper;
import cn.kxx.pojo.Permission;
import cn.kxx.pojo.Role;
import cn.kxx.service.RoleServise;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Auther: Kong Xiang Xiang
 * @Date: 2022/11/6 17:29
 * @DESC:
 */
@Service
public class RoleServiseImpl implements RoleServise {
    @Autowired
    private RoleMapper roleMapper;


    //查询所有角色信息
    @Override
    public List<Role> findAll() {

        List<Role> list = roleMapper.findAll();

return list;


    }


    //查询角色详情
    @Override
    public Role findById(Integer id) {


       Role role = roleMapper.findById(id);

       return role;
    }

    //新增角色
    @Override
    public void save(Role role) {
        roleMapper.save(role);

    }


    //角色添加权限 start
    @Override
    public List<Permission> findRoleByIdAndAllPermission(Integer id) {

       List<Permission> list = roleMapper.findRoleByIdAndAllPermission(id);
        return list;
    }

    @Override
    public void addPermissionToRole(Integer roleId, int[] ids) {

        for (int id : ids) {

            roleMapper.addPermissionToRole( roleId,id);
        }

    }

    //角色添加权限 end
}
